package com.example.demo.application_event_publisher;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 继承ApplicationListener接口监听事件
 * 监听器：当有用户注册事件发生时，记录日志
 */
@Component
@Slf4j
public class RecordUserRegisterListener1 implements ApplicationListener<UserRegisterEvent> {

    @Async
    @SneakyThrows
    @Override
    public void onApplicationEvent(UserRegisterEvent event) {
        User user = event.getUser();
        Thread.sleep(3000L);
        log.info("用户[" + user.getName() + "]注册成功，记录日志 延时3秒");
    }
}